package q929_numUniqueEmails;

import java.util.HashSet;
import java.util.Set;

public class Solution {
    /*
    分别处理@符号前后的字符串 然后利用set去重即可
     */
    public int numUniqueEmails(String[] emails) {
        Set<String> set = new HashSet<>();
        for (String email : emails) {
            String[] string = email.split("@");
            StringBuilder sb = new StringBuilder();
            // 处理本地部分
            for (int j = 0; j < string[0].length(); j++) {
                if (string[0].charAt(j) == '+') break;
                if (string[0].charAt(j) == '.') continue;
                sb.append(string[0].charAt(j));
            }

            sb.append('@');
            // 处理域名部分
            sb.append(string[1]);
            set.add(sb.toString());
        }
        return set.size();
    }
}
